package com.kylin.domain.commodity.provider;

import com.kylin.domain.authority.command.*;
import com.kylin.domain.commodity.vo.CommodityVO;
import com.kylin.domain.marketing.command.FindMarketingCommodityCommand;
import com.kylin.domain.marketing.vo.MarketingCommodityVO;
import com.kylin.shared.common.FunctionProvider;
import com.kylin.shared.common.PageResults;
import lombok.extern.slf4j.Slf4j;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.axonframework.eventhandling.gateway.EventGateway;
import org.axonframework.queryhandling.QueryGateway;
import org.springframework.stereotype.Component;

/**
 * 麒麟商品操作类
 * @author Damon S.
 * @version v1.0.1
 * @date 2020年01月14日 18:28
 */
@Slf4j
@Component
public final class CommodityProvider extends FunctionProvider {

    public CommodityProvider(QueryGateway queryGateway,
                             CommandGateway commandGateway,
                             EventGateway eventGateway) {
        super(queryGateway, commandGateway, eventGateway);
    }

    public Long createCommodity(CreateCommodityCommand command) {
        return sendCommand(command);
    }

    public PageResults findCommodities(QueryCommodityCommand command) {
        return executeQuery(command, PageResults.class);
    }

    public void addComment(CommentCommodityCommand command) {
        sendCommand(command);
    }

    public void removeComment(RemoveCommentCommand command) {
        sendCommand(command);
    }

    public PageResults findComments(QueryCommentCommand command) {
        return executeQuery(command, PageResults.class);
    }

    public CommodityVO findCommodityByCommodityId(Long commodityId) {
        QueryCommodityByIdCommand command = QueryCommodityByIdCommand.builder()
                .commodityId(commodityId).build();
        return executeQuery(command, CommodityVO.class);
    }

    public MarketingCommodityVO findMarketingCommodity(Long commodityId) {
        FindMarketingCommodityCommand command = FindMarketingCommodityCommand.builder()
                .commodityId(commodityId).build();
        return executeQuery(command, MarketingCommodityVO.class);
    }

    public String findCommodityHtmlByCommodityId(Long commodityId) {
        QueryHtmlByCommodityIdCommand command = QueryHtmlByCommodityIdCommand.builder()
                .commodityId(commodityId).build();
        return executeQuery(command, String.class);
    }
}
